﻿#region Header
/*
 * name：ResourceProviderFactory
 * author：Kain
 * date：12/1/2010 4:33:49 PM
 *********************************************
 * History:
 * $Header$
 * $History$
 */
#endregion

#region imported namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Compilation;
using Microsoft.Practices.Unity;
using Cherry.Agile.Core;
#endregion

namespace Cherry.Agile.Globalization
{
    /// <summary>
    /// 
    /// </summary>
    internal class ResourceProviderFactory : System.Web.Compilation.ResourceProviderFactory
	{
        static IResourceProvider __provider;
        static object __sync = new object();

        IResourceProvider GetProvider(string resourceKey)
        {
            if (__provider == null)
            {
                lock (__sync)
                {
                    if (__provider == null)
                    {
                        if (Container.Current.IsRegistered<IResourceProvider>())
                        {
                            __provider = Container.Current.Resolve<IResourceProvider>(
                                new ParameterOverride("resourceKey", resourceKey));
                        }
                        else
                        {
                            return new ResourceProvider(resourceKey);
                        }
                    }
                }
            }
            return __provider;
        }

        public override System.Web.Compilation.IResourceProvider CreateGlobalResourceProvider(string classKey)
        {
            return GetProvider(classKey);
        }

        public override System.Web.Compilation.IResourceProvider CreateLocalResourceProvider(string virtualPath)
        {
            return GetProvider(virtualPath);
        }
    }
}
